<template>
  <div>
    <div class="header">
      <div>志愿服务</div>
      <div>
        <img src="../assets/yxtx/phone.png" alt="图片丢失" />
        <span>联系组织</span>
      </div>
    </div>
    <div class="content">
      <!-- 轮播图 -->
      <div class="lunbo">
        <el-carousel height="475px">
          <el-carousel-item>
            <img src="../assets/yxtx/images/picture1.jpg" alt="图片丢失" />
          </el-carousel-item>
          <el-carousel-item>
            <img src="../assets/yxtx/images/picture2.jpg" alt="图片丢失" />
          </el-carousel-item>
          <el-carousel-item>
            <img src="../assets/yxtx/images/picture3.jpg" alt="图片丢失" />
          </el-carousel-item>
        </el-carousel>
      </div>
      <!-- 游学项目卡片 -->
      <div class="yxcard">
        <div
          class="projectCard"
          v-for="item in projects"
          :key="item.id"
          @click="cardClickHandler(item.id)"
        >
          <div class="photo">
            <img :src="item.figure" alt="图片丢失" />
          </div>
          <div class="introduce">
            <div class="pro_title">{{ item.name }}</div>
            <div class="pro_time">
              {{ fmtDate(item.beginTime) }} ~ {{ fmtDate(item.endTime) }}
            </div>
            <div class="pro_introduce">{{ item.introduce }}</div>
          </div>
        </div>
      </div>
    </div>
    <div class="footer"></div>
  </div>
</template>
<script>
import request from '../utils/request'
import moment from 'moment'
export default {
  data () {
    return {
      projects: []
    }
  },
  methods: {
    findAllProject () {
      request.get('/index/project/pageQuery?page=1&pageSize=5&status=审核通过').then(res => {
        this.projects = res.data.list
      })
    },
    fmtDate (date) {
      return moment(date).format('YYYY-MM-DD HH:mm:ss')
    },
    // 卡片点击处理函数
    cardClickHandler (id) {
      // 点击当前项目卡片实现路由跳转，跳转至项目的详情页
      // 路由跳转同时传递参数
      this.$router.push({ path: '/project', query: { id } })
    }
  },
  created () {
    this.findAllProject()  // 调用查询游学项目方法
  }
}
</script>
<style scoped>
.header {
  height: 100px;
  box-shadow: 0px 0px 5px 1px #999;
  display: flex;
}
.header div {
  width: 200px;
  height: 100px;
  line-height: 100px;
  text-align: center;
}
.header div:first-child {
  font-size: 30px;
  flex: 1;
}
.header div:last-child {
  font-size: 20px;
  flex: 4;
  text-align: right;
  padding-right: 50px;
}
.header div:last-child img {
  width: 50px;
  height: 50px;
  margin-top: 15px;
}
.lunbo img {
  width: 100%;
  height: 475px;
}
.yxcard {
  padding: 50px 100px;
}
.projectCard {
  display: flex;
  height: 200px;
  border-radius: 10px;
  box-shadow: 0px 0px 5px 1px rgb(214, 214, 213);
  margin-bottom: 50px;
}
.photo {
  width: 300px;
  height: 200px;
}
.photo img {
  width: 300px;
  height: 200px;
}
.introduce {
  padding: 10px 20px;
}
.pro_title {
  font-size: 18px;
  color: #666;
  height: 50px;
  line-height: 50px;
  font-weight: bold;
}
.pro_time {
  height: 20px;
  line-height: 20px;
}
.pro_introduce {
  height: 100px;
  padding-top: 30px;
  line-height: 20px;
}
</style>